layui.use(['table', 'admin', 'ax', 'func','laydate','formSelects', 'form'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var func = layui.func;
    var form = layui.form;

    /**
     * 运营组管理
     */
    var NanSeller = {
        tableId: "nanSellerTable"
    };

    /**
     * 初始化表格的列
     */
    NanSeller.initColumn = function () {
        return [[
            {align: 'center', toolbar: '#tableBar', title: '操作'},
            {field: 'name', sort: false, title: '名称'},
            {field: 'phone', sort: false, title: '联系电话'},
            {field: 'man', sort: false, title: '联系人'},
        ]];
    };

    /**
     * 点击查询按钮
     */
    NanSeller.search = function () {
        var queryData = {};

        queryData['name'] = $('#name').val();

        table.reload(NanSeller.tableId, {
            where: queryData, page: {curr: 1}
        });
    };


    // 渲染表格
    var tableResult = table.render({
        elem: '#' + NanSeller.tableId,
        url: Feng.ctxPath + '/nanSeller/list',
        page: true,
        limit: 20,
        height: "full-158",
        cellMinWidth: 100,
        cols: NanSeller.initColumn()
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        NanSeller.search();
    });


    table.on('sort('+NanSeller.tableId+')', function(obj){
            table.reload(NanSeller.tableId, {
                initSort: obj,
                where: {
                    field: obj.field.replace(/([A-Z])/g,"_$1").toLowerCase()
                    ,order: obj.type
                }
            });
        });

    // 工具条点击事件
    table.on('tool(' + NanSeller.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'edit') {
            window.parent.choose(data, "seller");
            admin.closeThisDialog();
        }
    });
});
